package com.algorithm.string_and_array;

import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;

@Slf4j
public class ArraySolutionLC06 {
    /**
     *  sum = 2*leftSum+num[i]
     * @param nums
     * @return
     */
    public int pivotIndex(int[] nums) {
        int sum  = 0;
        for (int i = 0; i < nums.length ; i++) {
            sum = sum+nums[i];
        }

        int leftSum = 0;
        for (int i = 0; i < nums.length ; i++) {
            if (2*leftSum+nums[i]==sum){
                return i;
            }
            leftSum = leftSum+nums[i];

        }

        return -1;
    }

    @Test
    public void test(){

    }

}
